const { JDReg, PDDReg, TBReg, URLReg } = require("./reg");
const { getGoodDetail } = require("../controller/JD/index")



const sendCouponMsg = async (xmlJson) => {
    const { Content } = xmlJson
    const url = URLReg(Content)[0]
    const isJD = JDReg(Content)
    const isPDD = PDDReg(Content)
    const isTB = TBReg(Content)

    if (isJD) {
        const JdRes = await getGoodDetail(url)
        let content = ''
        if (JdRes.returnMoney !== 0 && JdRes.goodUrl) {
            let tempName = JdRes.goodName.slice(0, 10) + '...'
            content = `商品名称：${tempName}\n优惠券：${JdRes.coupon}\n券后价格：${JdRes.afterPrice}\n额外返现：${JdRes.returnMoney}\n----------------\n<a href="${JdRes.goodUrl}">点击领券下单</a>\n**********************\n<a href="https://www.baidu.com">点击查看我的订单</a>`
        } else {
            content = '亲，该商家无活动哦！'
        }
        xmlJson.Content = content
        return xmlJson
    }
}


module.exports = {
    sendCouponMsg
}